home *** CD-ROM | disk | FTP | other *** search
- /* MyFiles.c
- * Handle file calls in IAC speller testbed app
- * ©1992 Working Software, Inc.
- * This source code is copyrighted. Permission is granted to use the Word Services
- * portion of the Writeswell Jr. source code in your own programs, but you
- * may not distribute the Writeswell Jr. word-processor code as a
- * commercial product. If you modify the code, please do not call it
- * Writeswell Jr. (or Writeswell.) This will ensure that people understand the
- * program and don’t have to deal with a number of different versions with
- * who-knows-what going on in the code.
- *
- * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
- * 6 Sep 91 Mike Crawford
- */
-
- #include <Files.h>
- #include "MyFiles.h"
- #include "AppleEvents.h"
- #include "TBConstants.h"
- #include "TBGlobals.h"
- #include "TestBed.h"
- #include "Scroll.h"
- #include "Gripe.h"
-
- OSErr MyOpenFile( FSSpec *specPtr )
- {
- OSErr err;
- Rect txRect;
- char textBuf[ 512 ];
- long bytesRead;
- TEHandle textH;
-
- if ( err = FSpOpenDF( specPtr, fsRdWrPerm, &gRefNum ) ){
- Gripe( "\pFSpOpenDF failed" );
- return err;
- }
-
- if ( MakeNewWindow() ){
- Gripe( "\pMakeNewWindow failed" );
- return err;
- }
-
- SetWTitle( gDocWindow, specPtr->name );
-
- textH = (TEHandle)GetWRefCon( gDocWindow );
-
- do {
- bytesRead = 512;
-
- err = FSRead( gRefNum, &bytesRead, textBuf );
-
- if ( !err || err == eofErr ){
- TEInsert( textBuf, bytesRead, textH );
- }
- } while ( !err );
-
- TESetSelect( 0L, 0L, textH );
-
- return noErr;
- }
-
- OSErr MakeNewWindow( void )
- {
- OSErr err;
- Rect txRect;
- TEHandle textH;
-
- gDocWindow = GetNewWindow( kDocWindowID, (Ptr)NULL, (WindowPtr) -1 );
- if ( !gDocWindow ){
- Gripe( "\pGetNewWindow failed" );
- return err;
- }
-
- SetPort( gDocWindow );
-
- GetTERect( &( thePort->portRect ), &txRect );
-
- textH = TENew( &txRect, &txRect );
-
- if ( !textH ){
- Gripe( "\pTENew failed" );
- return memFullErr;
- }
-
- SetWRefCon( gDocWindow, (long)textH );
-
- gVertScroll = GetNewControl( kVertScrollBarID, gDocWindow );
- if ( !gVertScroll )
- return memFullErr;
-
- ( *textH )->clikLoop = (ProcPtr)TrackContentClick;
-
- SizeVertScroll();
-
- SetVertScroll( gDocWindow, gVertScroll );
-
- return noErr;
-
- }